<template>
    <div class="mallWallet">
        <van-nav-bar title="储存钱包" left-arrow @click-left="onClickLeft" />
        <div class="card">
            <div class="cardTop">
                <van-image round src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg" />
                <span>钱包金额</span>
            </div>
            <span>¥ {{ userInfo.hasmoney }}</span>
            <div class="cardBtm">
                <div>
                    可提现余额(元)
                </div>
                <div class="btn">
                    <van-button type="default" @click="routerTo('tixian')">去提现<span class="icon"><van-icon
                                name="arrow" /></span>

                    </van-button>
                </div>
            </div>
        </div>
        <div class="shouyi">
            <div><span>昨日收益:</span><span>¥0.00</span></div>
            <div>
                <!-- <span>今日收益:</span><span>¥1234.23</span> -->
            </div>
        </div>
        <div class="title">
            <span>收入明细</span>
            <van-button type="default">日期选择</van-button>
        </div>
        <div class="list">

            <van-empty description="暂无数据" style="height: 100%;" v-if="flowingList.length == 0" />
            <div class="listItem" v-for="item in flowingList" :key="item.id">
                <div class="left">
                    <span>{{ item.change_type }}</span>
                    <span><span>{{ item.record_type == 0 ? '消费了' : '返回了' }}</span>{{ item.money }}</span>
                </div>
                <div class="right">
                    <span><span>{{ item.record_type == 0 ? '-' : '+' }}</span>{{ item.money }}</span>
                    <span>{{ item.createtime }}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router';
import { Toast } from 'vant';
import { flowing } from '../../../api/index';

export default {
    name: "storagewallet",
    setup() {

        const router = useRouter();
        // 定义onClickLeft方法
        const onClickLeft = () => history.back();
        const userInfo = JSON.parse(window.localStorage.getItem("userInfo") as string)
        const routerTo = (str: string) => {
            router.push('/mine/' + str + "/5");
        }


        //  累计充值积分
       const page_size = ref('')
        const moneytype = ref('')
        const flowingList = ref<any>([])
        const total = ref(0)
        const getflowList = () => {
            let formData = new FormData();
            formData.append("type", (page_size.value, moneytype.value))
            flowing(formData).then((res: any) => {
                // console.log(res.data.list.total);
                if (res.code == 1) {
                    flowingList.value = res.data.list.data;
                    total.value = res.data.list.total
                } else {
                    Toast(res.msg);
                }
            });
        };

        // 如果需要在组件挂载后执行某些操作，可以使用onMounted
        onMounted(() => {
            // 组件挂载后的逻辑
            console.log(useRouter())
            getflowList()
        });

        return {
            onClickLeft, userInfo, routerTo, flowingList
        };
    }
}
</script>

<style scoped lang="less">
@import url(../../../style/common.css);

.mallWallet {
    background: #F6F7F9;
    width: 100%;
    // height: calc(100vh-40px);
    height: 100vh;

    .van-nav-bar {
        height: 52px;
    }

    .card {
        width: 345px;
        height: 158px;
        background-image: url('../../../assets/my/storage.png');
        background-size: 100% 158px;
        background-repeat: no-repeat;
        display: flex;
        justify-content: space-around;
        align-items: flex-start;
        flex-direction: column;
        box-sizing: border-box;
        margin: 28px 15px;
        padding-left: 26px;
        position: relative;
        z-index: 999;

        .cardTop {
            display: flex;
            align-items: center;

            .van-image {
                width: 30px;
                height: 30px;
                border: 1px solid #FFFFFF;
                margin-right: 12px;
            }

            span {
                font-weight: 400;
                font-size: 16px;
                color: #FFFFFF;
            }
        }

        span {
            font-size: 30px;
            color: #FFFFFF;
        }

        .cardBtm {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;
            font-size: 14px;
            color: #FFFFFF;

            .van-button {
                width: 90px;
                height: 35px;
                background: #FFFFFF;
                border-radius: 25px 0px 0px 25px;
                font-size: 14px;
                color: #0A83FD;
                display: flex;
                justify-content: flex-start;
                align-items: center;

                .icon {
                    // display: inline-block;
                    margin: 0 0 0 5px;
                    font-size: 14px;
                    color: #0A83FD;
                    position: relative;
                    top: -10px;
                }
            }
        }

    }

    .shouyi {
        width: 345px;
        height: 69px;
        background: #F8F9FC;
        border-radius: 0px 0px 10px 10px;
        margin: auto 15px;
        display: flex;
        justify-content: flex-start;
        z-index: 1;
        position: relative;
        top: -60px;
        margin-bottom: -40px;

        div {
            margin-top: 32px;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            padding: 13px;

            span {
                margin-right: 17px;

                &:nth-child(1) {
                    font-size: 12px;
                    color: #666666;
                }

                &:nth-child(2) {
                    font-size: 12px;
                    color: #686868;
                }
            }
        }
    }

    .title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 15px;

        span {
            font-size: 16px;
            color: #3D3D3D;
            text-align: left;
        }

        .van-button {
            font-size: 12px;
            color: #777777;
            width: 80px;
            height: 31px;
            background: #F1F2F2;
            border-radius: 516px 516px 516px 516px;

        }
    }

    .list {

        // height: 100%;
        .listItem {
            margin: 16px 15px 0;
            height: 80px;
            background: #FFFFFF;
            border-radius: 13px 13px 13px 13px;
            display: flex;
            justify-content: space-between;
            padding: 18px 16px;
            box-sizing: border-box;

            .left,
            .right {
                display: flex;
                justify-content: space-between;
                flex-direction: column;
                text-align: left;

                span {
                    &:nth-child(1) {
                        font-size: 14px;
                        color: #3D3D3D;
                    }

                    &:nth-child(2) {
                        font-size: 12px;
                        color: #999999;
                    }
                }
            }

            .right {
                text-align: right;
            }
        }
    }
}

:deep(.van-button__text .van-icon::before) {
    // margin-top: 5px;
    // margin-left: 3px;
    // width: 6px;
    // height: 11px;
    // float: left;
    position: absolute;
    top: -1px;
}

:deep(.van-nav-bar__left .van-badge__wrapper) {
    color: #272635;
}
</style>